package com.javapatterns.decorator.grep;

import java.io.FileReader;
import java.io.IOException;

public class Grep {
	static GrepReader g; // own FilterReader definition

	private static GrepView gv = new GrepView();

	public static void main(String[] args) {

		String line;
		try {
			String file = "xml2.xml";
			String path = Grep.class.getClassLoader().getResource("").getPath()
					+ file;
			System.out.println(path);
			String match = "yaoming";
			gv.println("\nGrep: 搜索 " + path + " 文件 " + match);
			gv.println("文件行号\t\t 下面的行里含有所搜索的字符串\n");

			g = new GrepReader(new FileReader(path), match);
			for (;;) {
				line = g.readLine();
				if (line == null)
					break;
				gv.println(file + g.lineNo() + ":\t" + line);
			}
			g.close();
		} catch (IOException e) {
			gv.println(e.getMessage());
		}
	}
}
